package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcPatrolGreatLocationMapper;
import com.csun.cmny.provider.dao.DmcPatrolPointLocationMapper;
import com.csun.cmny.provider.model.domain.DmcPatrolPointLocation;
import com.csun.cmny.provider.model.dto.device.DeviceBindDto;
import com.csun.cmny.provider.model.dto.patrol.PatrolPointPageQuery;
import com.csun.cmny.provider.model.dto.propertyManagement.SelectDeviceDataDto;
import com.csun.cmny.provider.model.vo.OldmanBedRoomBuildingVo;
import com.csun.cmny.provider.model.vo.RoomBuildingVo;
import com.csun.cmny.provider.model.vo.patrol.DmcPatrolPointVo;
import com.csun.cmny.provider.model.vo.patrol.DmcPatrolVo;
import com.csun.cmny.provider.model.vo.propertyManagement.PropertyDataVo;
import com.csun.cmny.provider.service.DmcPatrolPointLocationService;
import com.csun.cmny.provider.service.OmcRpcService;
import com.csun.cmny.provider.utils.DeviceUtils;
import com.csun.cmny.util.PublicUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2021/7/22 9:42
 * @Description: 巡更点绑定位置接口实现
 */
@Service
public class DmcPatrolPointLocationServiceImpl extends BaseService<DmcPatrolPointLocation>
        implements DmcPatrolPointLocationService {

    @Resource
    private DmcPatrolPointLocationMapper dmcPatrolPointLocationMapper;
    @Resource
    private DeviceUtils deviceUtils;
    @Resource
    private OmcRpcService omcRpcService;
    /*
     * 巡更点的分页查询
     * */
    @Override
    public PageInfo queryDeviceListWithPage(PatrolPointPageQuery patrolPointPageQuery) {
        PageHelper.startPage(patrolPointPageQuery.getPageNum(), patrolPointPageQuery.getPageSize());
        List<DmcPatrolPointVo> dmcPatroPointlVos = dmcPatrolPointLocationMapper.queryDeviceListWithPage(patrolPointPageQuery);
        for (DmcPatrolPointVo dmcPatrolPointVo:dmcPatroPointlVos) {
            if (dmcPatrolPointVo.getBedId()!=null){
                OldmanBedRoomBuildingVo obv = omcRpcService.queryOldmanBedRoomBuildingByBedId(dmcPatrolPointVo.getBedId());
                dmcPatrolPointVo.setLocation(obv.getRoomNo()+"-"+obv.getBedNo());
            }else if (dmcPatrolPointVo.getRoomId()!=null){
                RoomBuildingVo rbv = omcRpcService.queryRoomBuildingByRoomId(dmcPatrolPointVo.getRoomId());
                dmcPatrolPointVo.setLocation(rbv.getRoomNo());
            }
        }
        return new PageInfo<>(dmcPatroPointlVos);
    }
    /*
    * 巡更点的绑定
    * */
    @Override
    public Integer patrolPointBind(DmcPatrolPointLocation dmcPatrolPointLocation) {
        return dmcPatrolPointLocationMapper.insert(dmcPatrolPointLocation);
    }

    /*
    * 查询该位置是否绑定
    * */
    @Override
    public DmcPatrolPointLocation selectByBedId(Integer bedId,Integer roomId) {
        return dmcPatrolPointLocationMapper.selectByBedId(bedId,roomId);
    }
    /*
     * 运营平台设备可视化查询
     * */
    @Override
    public List<PropertyDataVo> selectDeviceData(SelectDeviceDataDto selectDeviceDataDto) {
        return dmcPatrolPointLocationMapper.selectDeviceData(selectDeviceDataDto);
    }
}
